﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace EpicBall.ScreenSystem
{
    public class MenuButton
    {
        protected Vector2 _position;
        protected bool _hover;
        protected Texture2D _sprite;
        protected GameScreen _screen;
        protected MenuScreen _menu;

        public MenuButton(MenuScreen menu, Texture2D sprite, Vector2 position)
        {
            _menu = menu;
            _sprite = sprite;
            _position = position;
        }
        public MenuButton(MenuScreen menu, GameScreen screen, Texture2D sprite, Vector2 position) : this(menu, sprite, position)
        {
            _screen = screen;
        }

        public MenuButton(MenuScreen menu, GameScreen screen, Texture2D sprite, Vector2 position, Vector2 relativeTo) : this(menu, screen, sprite, position)
        {
            _position = new Vector2(relativeTo.X + position.X, relativeTo.Y + position.Y);
        }

        public GameScreen Screen
        {
            get { return _screen; }
        }

        public Vector2 Position
        {
            get { return _position; }
            set { _position = value; }
        }

        public bool isHover
        {
            get { return _hover; }
        }

        /// <summary>
        /// Check for collision with the menu button
        /// </summary>
        /// <param name="src"></param>
        public void Collide(Vector2 src)
        {
            Rectangle collideBox = new Rectangle((int)(_position.X - _sprite.Width / 2), (int)(_position.Y - _sprite.Height / 2), _sprite.Width, _sprite.Height);
            if (collideBox.Contains((int)src.X, (int)src.Y))
            {
                _hover = true;
            }
            else
            {
                _hover = false;
            }
        }

        public virtual void Update(GameTime gameTime)
        {
            //Check for mouseeposition colliding with button
            Collide(_menu.mousePos);
        }

        public virtual void Draw(GameTime gameTime)
        {
            _menu.GameStack.SpriteBatch.Draw(_sprite, new Rectangle((int)(_position.X - _sprite.Width / 2), (int)(_position.Y - _sprite.Height / 2), _sprite.Width, _sprite.Height), Color.White);
        }

        public virtual void ButtonClicked()
        {
            _menu.GameStack.AddScreen(_screen);
        }
    }
}
